#include "usersettingsdialog.h"
#include "ui_usersettingsdialog.h"

#include <QSettings>
#include <QFont>


UserSettingsDialog::UserSettingsDialog(QWidget *parent) :
    QDialog(parent),
    m_ui(new Ui::UserSettingsDialog)
{
    m_ui->setupUi(this);
    m_ui->fcbFont->setFont(qApp->font());
}

UserSettingsDialog::~UserSettingsDialog()
{
    delete m_ui;
}

void UserSettingsDialog::changeEvent(QEvent *e)
{
    QDialog::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void UserSettingsDialog::accept()
{    
    QSettings settings;
    settings.beginGroup("user settings");
    if (m_ui->fcbFont->currentFont() != settings.value("font").value<QFont>()) {
        settings.setValue("font", m_ui->fcbFont->currentFont().toString());
        QString str = m_ui->fcbFont->currentFont().toString(); //delete
        qApp->setFont(m_ui->fcbFont->currentFont());
    }
    //if (m_ui->kcolorbutton->color() != settings.value("selectcolor")){
    //  settings.setValue("selectcolor",m_ui->kcolorbutton->color());
    //qApp->setStyleSheet(QString("QTableView { selection-background-color: qlineargradient(x1: 0, y1: 0, x2: 0.5, y2: 0.5, stop: 0 %1, stop: 1 white);}")
    //                      .arg(m_ui->kcolorbutton->color().name()));
    //}
    settings.endGroup();
    hide();
    setResult(QDialog::Accepted);

}
